<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-12">
                        <lqf_link>
                            <a class="btn btn-default btn-block" id="upload_file_btn"
                               data-url="{$ajaxtarget}" data-key="upload_file_btn">
                                <i class="fa fa-upload"></i>
                            </a>
                        </lqf_link>
                    </div>
                </div>
            </div>
            <div class="ibox-content table-responsive">
                <table class="table table-hover sorttable ajax-list-table-file" data-url="{$ajaxtarget}" width="100%">
                    <thead>
                    <tr>
                        <th width=""><span>{:lang('文件名称')}</span></th>
                        <th width="200"><span>{:lang('修改时间')}</span></th>
                        <th width="150"><span>{:lang('大小')}</span></th>
                        <th width="100" class="text-center">{:lang('操作')}</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                    <tfoot class="ibox-content">
                    <tr>
                        <td colspan="4" align="center"></td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<link rel="stylesheet" href="__STATIC__/addon/file/Huploadify.css"/>
<script src="__STATIC__/addon/file/jquery.Huploadify.js"></script>
<script type="text/javascript">
    var target = '{$uploadtarget}';
    var ajaxtarget = '{$ajaxtarget}';
    $(document).ready(function () {
        getUploadFile();
        //上传文件组
        $("#upload_file_btn").Huploadify({
            auto: true,
            height: 30,
            fileObjName: "file",
            buttonText: "上传文件",
            uploader: "{$uploadtarget}",
            width: 120,
            removeTimeout: 1,
            fileSizeLimit: "52000",
            fileTypeExts: "*.jpg; *.png; *.gif; *.zip; *.rar; *.tar; *.gz; *.7z; *.doc; *.docx; *.txt; *.xml; *.xlsx; *.xls;*.mp4;*.json;",
            onUploadComplete: uploadBackFunction
        });

        //上传成功回调地址
        function uploadBackFunction(file, data) {
            getUploadFile();
        }

        //删除目录文件
        $("body").on("click", ".uploadfile-del", function () {
            var basename = $(this).attr('data-val');
            $.ajax({
                type: "POST",
                url: ajaxtarget,
                data: {"basename": basename, "ajaxmodel": 'del'},
                dataType: "json",
                async: true,
                beforeSend: function () {

                },
                success: function (jsondata) {
                    layer.msg(jsondata.msg);
                },
                complete: function () {
                    getUploadFile();
                }
            });
        });

        //目录文件导入
        $("body").on("click", ".uploadfile-import", function () {
            var basename = $(this).attr('data-val');
            $.ajax({
                type: "POST",
                url: ajaxtarget,
                data: {"basename": basename, "ajaxmodel": 'import'},
                dataType: "json",
                async: true,
                beforeSend: function () {

                },
                success: function (jsondata) {
                    layer.msg(jsondata.msg);
                }
            });
        })
    });

    //获取上传目录文件
    function getUploadFile() {
        var obj = $('.ajax-list-table-file');
        var target = obj.attr('data-url');
        $.ajax({
            type: "POST",
            url: target,
            data: {"uploadfilepath": '{$uploadfilepath}', "ajaxmodel": 'get'},
            dataType: "json",
            async: true,
            beforeSend: function () {
                //$('.ajax-list-table-file').empty();
            },
            success: function (jsondata) {
                var html = '';
                $.each(jsondata.data, function (idx, row) {
                    html += '<tr>';
                    html += '<td>' + row.basename + '</td>';
                    html += '<td>' + row.uptime + '</td>';
                    html += '<td>' + row.size + '</td>';
                    html += '<td class="text-center"> ' +
                        '<a href="#" class="uploadfile-import" data-val="' + row.basename + '">导入</a> | ' +
                        '<a href="#" class="uploadfile-del" data-val="' + row.basename + '">删除 </a> ' +
                        '</td>';
                    html += '</tr>';
                });
                obj.find('tbody').html(html);
            },
            complete: function () {

            }
        });
    }
</script>
